home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-02-08 | 3.1 KB | 111 lines | [TEXT/KEEN] |
- #MFS_SuperReplace.T
- #
- ############ THIS IS NOT AN EXECUTABLE PROGRAM ##############
- #
- #the program to run for "superReplacing" is called $MFS_SuperReplace.
- #This is the "Template" from which the Actual program
- #(MFS_SuperReplace.A) is produced by $MFS_SuperReplace. In the line
- # while (match(multi, find) > 0)
- #"find" is replaced by the actual find string, and in the line
- # sub(find, replace, multi);
- #both the find and replace strings are replaced. This produces a program
- #with static rather than dynamic regular expression to search for,
- #and a constant replace string, and it runs faster as a result.
-
- BEGIN {
- if (ignorecase+0 != 0)
- IGNORECASE = 1;
- ORS = "";#so that "print" does not spit out "\n's"
- progressFile = STDPATH "$tempProgress"
- }
-
- FNR == 1 { if (n > 0)
- {
- for (i = 1; i <= n; ++i)
- print out[i] > outfile;
- if (multi != "")
- print multi > outfile;
- print "\n" > outfile;
- close(outfile);
- for (i in out)
- delete out[i];
- n = 0;
- }
- outfile = FILENAME;
- if (document != 0)
- {
- z = split(FILENAME, names, ":");
- if (!progress("\nSuperReplacing: " names[z] "\nFiles left: " num_files))
- { # concurrent mode, print progress to file
- print "SuperReplacing:", names[z], "\nFiles left:", num_files > progressFile
- close(progressFile)
- }
- --num_files
- }
- }
-
- {multi = $0;#the first line is already there
- outLine = multiLines = 1;
- #For document purposes, outLine tracks the true output line number of
- #the first line in multi, ie the line number after replacement
- while (getline x > 0)#should exit if < 0
- {
- multi = multi "\n" x;
- ++multiLines;
- while (match(multi, find) > 0)##MARK find
- {
- if (document != 0)#print filename, new line number, text before changes
- {
- ++numDid;
- if (RSTART > 1)
- {
- prematch = substr(multi, 1, RSTART - 1);
- t1 = gsub(/\n/, "\n", prematch);
- temp = t1 + outLine;
- }
- else
- temp = outLine;
- print names[z], temp, " was:" "\n";
- print substr(multi, RSTART, RLENGTH) "\n";
- }
- lenBefore = length(multi)
- sub(find, replace, multi);##MARK repToo
- repLen = RLENGTH + length(multi) - lenBefore
- out[++n] = substr(multi, 1, RSTART + repLen - 1);
- if (document != 0)
- {
- t1 = gsub(/\n/, "\n", out[n]);
- outLine += t1;
- }
- multi = substr(multi, RSTART + repLen);
- #that may have messed up the number of lines
- multiLines = gsub(/\n/, "\n", multi) + 1;
- }
- while (multiLines > maxLines)##MARK maxLines
- {
- j = index(multi, "\n");
- out[++n] = substr(multi, 1, j);
- multi = substr(multi, j + 1);
- --multiLines;
- ++outLine;
- }
- }
- }
-
- END { if (n > 0)
- {
- for (i = 1; i <= n; ++i)
- print out[i] > outfile;
- if (multi != "")
- print multi > outfile;
- print "\n" > outfile;
- close(outfile);
- }
- if (numDid && document != 0)
- print "Total replacements: ", numDid, "\n"
- }
-
- #Dynabyte will freely distribute any nifty hAWK programs that you submit.
- #You get: author credit at top of the program; the satisfaction of
- #knowing you have made the world a better place; and in the Apple tradition,
- #a free kudo.